<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        * {
            margin: 0;
            padding: 0;
        }
        #box {
            display: flex;
            flex-direction: column;
            justify-content: center;
        }
        .header {
            width: 100%;
            height: 40px;
            display: flex;
            justify-content: space-around;
            align-items: center;

        }
        .header input{
            width: 70%;
            height: 20px;
            padding: 5px;
            border-radius: 5px;
            background-color: #ccc;
            border: none;
            outline: none;
        }
        .header span {
            color: green;
            display: inline-block;
            height: 20px;
            padding: 5px;
            border-radius: 5px;
            background-color: aliceblue;
        }
        .status ul{
            width: 100%;
            height: 20px;
            display: flex;
            list-style: none;
        }
        .status li {
            flex: 1;
            margin: 5px;
            padding: 5px;
            height: 20px;
            background-color: lightblue;
            border-radius: 5px;
            text-align: center;
            font-size: 14px;
        }
        h4{
            margin: 20px 10px;
        }
        
        .list li {
            width: 94%;
            height: 30px;
            background-color: lightblue;
            display: flex;
            margin: 5px 5px;
            align-items: center;
            padding: 0 5px;

        }
        .list li input{
            width: 10%;
        }
        .list li button{
            height: 26px;
        }
        .list li span{
            flex: 1;
        }
        .empty{
            width: 100%;
            height: 50px;
            text-align: center;
            
        }
        #box .none{
            background-color: red;
            color: white;
        }

       
    </style>
</head>
<body>
    <div id="box">
        <div class="header">
            <input type="text" v-model="text" placeholder="输入任务名称">
            <span @click="pushElement()">新增</span>

        </div>
        <div class="status">
            <ul>
                <li>全部任务({{list.length}})</li>
                <li>已完成({{list.length-recrod}})</li>
                <!-- 计算属性作为变量不加括号，有重复只计算一次 -->
                <li class="none">未完成({{recrod}})</li>
            </ul>
        </div>
        <h4>任务列表</h4>
        <div class="list">
            <ul>
                <li v-for="(item,index) in list" :key="index" :class="{none:item.status==false}">
                    <!-- key的添加提高了渲染效率                         如果list元素的status属性为false 赋予noneclass名字    -->
                    <input type="checkbox" @click="changeStatus(item)">
                    <span>{{item.id}} {{item.text}}</span>
                    
                    <button @click="del(index)">删除</button>
                </li>
            </ul>
        </div>
        <div class="empty" v-show="list.length == 0">没有任务，快去添加任务吧！</div>
    </div>
    <script src="vue-2.5.21.js"></script>
    <script src="ToDoList.js"></script>
</body>
</html>